package com.wedjg.concurrency.example.publish;

import java.util.Arrays;

/**
 * 不安全的发布类
 * 虽然成员变量为私有，但是返回了变量的引用，该引用可被修改；
 * @author wedjg
 * @version 1.0
 * @date 2019/6/2
 */

public class UnsafePublish {

    private String[] states = {"a", "b", "c"};

    public String[] getStates() {
        return states;
    }

    public static void main(String[] args) {
        UnsafePublish unsafePublish = new UnsafePublish();
        //获取states的引用
        String[] s1 = unsafePublish.getStates();
        System.out.println(Arrays.toString(unsafePublish.getStates()));
        //修改引用
        s1[1] = "a";
        System.out.println(Arrays.toString(unsafePublish.getStates()));
    }
}
